package com.xbongbong.pro.statistic.pojo.vo;

import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.pro.statistic.pojo.ChartFieldAttrPojo;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 字段返回对象
 * @author 梁鲁江
 * @date 2019/1/15 9:55
 * @since v1.0
 * @version v1.0
 */
@Setter
@Getter
@ToString
public class DataSourceObjectVO extends BaseVO {
    private static final long serialVersionUID = 2970658966660092555L;
    /**
     * 表单名称
     */
    private String name;
    /**
     * 表单id
     */
    private Long formId;

    /**
     * 表单字段
     */
    private List<? super FieldAttrEntity> fieldList;
    /**
     * 字段分类：    num 数字分类 ， date 日期分类 ， other 其它分类
     */
    private Map<String,List<FieldAttrEntity>> groupFiledMap;
    /**
     * 表单字段attr
     */
    private Set<String> fieldAttrList;

    public DataSourceObjectVO(){
        fieldList = new ArrayList<>();
        fieldAttrList = new HashSet<>();
    }

    public void addFieldList(ChartFieldAttrPojo chartFieldAttrPojo){
        this.fieldList.add(chartFieldAttrPojo);
        this.fieldAttrList.add(chartFieldAttrPojo.getAttr());
    }

    public void addFieldList(FieldAttrEntity fieldAttrEntity){
        this.fieldList.add(fieldAttrEntity);
        this.fieldAttrList.add(fieldAttrEntity.getAttr());
    }

    public void addFieldListIfAbsent(FieldAttrEntity fieldAttrEntity){
        if (this.fieldAttrList.add(fieldAttrEntity.getAttr())) {
            this.fieldList.add(fieldAttrEntity);
        }
    }
}
